<template>
	<view>
		
		
		
		<view class="container">
			<wn-calendar v-if="show" format="" :isEn="isEn" :isBorder="isBorder" :isLess="isLess" @change="onChange" @choose="onChoose" ref="calendar" :data="records"></wn-calendar>
		</view>
		
		
		
		
		
		

	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: true,
				clickValue: '',
				records: [
				],
				test: [{
						date: `2024/1/12`,
						text: '迟到',
						type: 3
					}, {
						date: `2024/1/24`,
						text: '早退',
						type: 2
					}, {
						date: `2024/1/7`,
						text: '早退',
						type: 3
					}, {
						date: `2024/1/8`,
						text: '早退',
						type: 1
					}, {
						date: `2024/1/2`,
						text: '迟到',
						type: 0
					}, {
						date: `2024/1/6`,
						text: '工作出色',
						type: 1
					}, {
						date: `2024/1/18`,
						text: '早退',
						type: 1
					}, {
						date: `2024/1/23`,
						text: '早退',
						type: 0
					}, {
						date: `2024/1/30`,
						text: '早退',
						type: 0
					}, {
						date: `2024/1/28`,
						text: '早退',
						type: 3
					}
				],
				isEn: false,
				isLess: false,
				isBorder: true,
				maintenanceTime:'选择时间',
				arraysname:[],
				nameindex:9,
				user:{},
				specificDate:'',
				maintenanceTimeEnd:'',
				stcdList:[],
				dataList:[],
				user:{}
			}
		},
		onNavigationBarButtonTap(e) {
			const index = e.index;
			if (index === 0) {
				uni.navigateTo({
					url: '/pages/qiandaoguanli/add'
				});

			}else if(index === 1){
				uni.navigateTo({
					url: '/pages/qiandaoguanli/add'
				});
			}
		},
		onShow(){
			this.getData()
		},
		onLoad(){
			
			this.user=JSON.parse(uni.getStorageSync("userinfo"))
			this.stcdList=this.user.stcdList
			this.arraysname=this.stcdList.map(item=>{
				return item.stnm
			})
			this.getData()
			
			
		},
		methods: {
			pasetime(date){
				const currentTime = new Date(date);
				const year = currentTime.getFullYear();
				const month = currentTime.getMonth() + 1; // 月份从0开始，因此需要加1
				const day = currentTime.getDate();
				
				return `${year}/${month}/${day}`
			},
			onChange(e) {
				console.log(e);
			},
			onChoose(e) {
				console.log(e);
				this.clickValue = JSON.stringify(e)
			},
			changeLess() {
				this.isLess = !this.isLess
				this.$refs.calendar.refresh()
			},
			changeLanguage() {
				this.isEn = !this.isEn
				this.show = false
				setTimeout(() => {
					this.show = true
				}, 200)
			},
			changeBorder() {
				this.isBorder = !this.isBorder
			},
			fillData() {
				this.records = this.test
				this.$refs.calendar.refresh()
			},
			TimeChange(val,type){
				
				this[type]=val.detail.value
				this.getData()
			},
			stnmPickerChange(val){
				this.nameindex=val.detail.value
				this.getData()
			},
			edit(item){
				uni.navigateTo({
					url: '/pages/qiandaoguanli/add?pagedata='+JSON.stringify(item)
				});
			},
			del(item){
				let that=this
				uni.showModal({
					title: '提示',
					content: '确定删除？',
					success: function (res) {
						if (res.confirm) {
							console.log(item)
							that.apipost('/soilWater/manage/attendance/remove/delAttendanceRecord',{
								id:item.id
							},true).then(res => {
								
								if(res.code==1){
									that.getData()
								}
								
							}).catch(err=>{
								console.log(err)
							});
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});

			},
			getData(){
				let that=this
				that.apipost('/soilWater/manage/attendance/view/pageAttendanceRecord',{
					userCode:this.user.userNo,
					currentPage:1,
					pageSize:500,
					stcd:''
				},false).then(res => {
					uni.stopPullDownRefresh()
					if(res.code==1){
						that.dataList=res.object.dataList
						that.records = res.object.dataList.map(item=>{
							item.date=that.pasetime(item.specificDate)
							item.text=item.status
							item.type=3
							return item
						})
						
						console.log(that.records)
						that.$refs.calendar.refresh()
					}
					
					
					
				}).catch(err=>{
					console.log(err)
				});
			}
		}
	}
</script>

<style>
	.main-title{
		padding:16rpx 0;
		font-size:28rpx;
		font-weight:bold;
	}
	.item-wrap{
		margin:30rpx auto 0 auto; 
		width: 702rpx;
		padding:20rpx;
		box-sizing: border-box;
		background: #FFFFFF;
		box-shadow: 0rpx 2rpx 10rpx 0rpx #D4E5FF;
		border-radius: 10rpx;
	}
	.search-wrap .ipt-wrap{
		height:84rpx;
		display:flex;
		align-items: center;
		justify-content: space-between;
		
		border-bottom: rgba(63,140,255,0.2) 1rpx solid;
	}
	.search-wrap{
		background:#fff;
		padding:0 40rpx;
	}
	page{
		height:100%;
		overflow: hidden;
		background:#F5F9FF;
	}
	.search-title{
		padding-left:48rpx;
		height:90rpx;
		display:flex;
		align-items: center;
		font-weight:bold;
		font-size:34rpx;
	}
	.btns-wrap{
		margin-top:40rpx;
		display:flex;
		justify-content: flex-end;
	}
	
	.btns-wrap .del-btn{
		display: flex;
		align-items: center;
		justify-content: center;
		color:#fff;
		width: 130rpx;
		height: 48rpx;
		background: #FA5151;
		border-radius: 4rpx;
		margin-right:20rpx;
	}
	
	.btns-wrap .edit-btn{
		display: flex;
		align-items: center;
		justify-content: center;
		color:#fff;
		width: 130rpx;
		height: 48rpx;
		background: #52C41B;
		border-radius: 4rpx;
		margin-right:20rpx;
	}

</style>
